﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract DokumentTip typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class DokumentTipDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<DokumentTipDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.DokumentTip _currentDokumentTip = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxDokumentTipDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxDokumentTipErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxDokumentTipBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Naziv property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxNazivDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the OblikSifre property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxOblikSifreDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Smjer property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxSmjerDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Rezervacija property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxRezervacijaDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Predracun property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxPredracunDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IDParent property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDParentDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IDPrebrojavanja property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDPrebrojavanjaDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.DokumentTip> _DokumentTipList;
				
		/// <summary> 
		/// The list of DokumentTip to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.DokumentTip> DokumentTipList
		{
			get {return this._DokumentTipList;}
			set
			{
				this._DokumentTipList = value;
				this.uxDokumentTipBindingSource.DataSource = null;
				this.uxDokumentTipBindingSource.DataSource = value;
				this.uxDokumentTipDataGridView.DataSource = null;
				this.uxDokumentTipDataGridView.DataSource = this.uxDokumentTipBindingSource;				
				//this.uxDokumentTipBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxDokumentTipBindingSource_ListChanged);
				this.uxDokumentTipBindingSource.CurrentItemChanged += new System.EventHandler(OnDokumentTipBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnDokumentTipBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentDokumentTip = uxDokumentTipBindingSource.Current as Entities.DokumentTip;
			
			if (_currentDokumentTip != null)
			{
				_currentDokumentTip.Validate();
			}
			//_DokumentTip.Validate();
			OnCurrentEntityChanged();
		}

		//void uxDokumentTipBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.DokumentTip"/> instance.
		/// </summary>
		public Entities.DokumentTip SelectedDokumentTip
		{
			get {return this._currentDokumentTip;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxDokumentTipDataGridView.VirtualMode;}
			set
			{
				this.uxDokumentTipDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxDokumentTipDataGridView.AllowUserToAddRows;}
			set {this.uxDokumentTipDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxDokumentTipDataGridView.AllowUserToDeleteRows;}
			set {this.uxDokumentTipDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxDokumentTipDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxDokumentTipDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="DokumentTipDataGridViewBase"/> class.
		/// </summary>
		public DokumentTipDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxDokumentTipDataGridView = new System.Windows.Forms.DataGridView();
			this.uxDokumentTipBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxDokumentTipErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxNazivDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxOblikSifreDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxSmjerDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxRezervacijaDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxPredracunDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDParentDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDPrebrojavanjaDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentTipDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentTipBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentTipErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxDokumentTipErrorProvider
			// 
			this.uxDokumentTipErrorProvider.ContainerControl = this;
			this.uxDokumentTipErrorProvider.DataSource = this.uxDokumentTipBindingSource;						
			// 
			// uxDokumentTipDataGridView
			// 
			this.uxDokumentTipDataGridView.AutoGenerateColumns = false;
			this.uxDokumentTipDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxDokumentTipDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDataGridViewColumn,
		this.uxNazivDataGridViewColumn,
		this.uxOblikSifreDataGridViewColumn,
		this.uxSmjerDataGridViewColumn,
		this.uxRezervacijaDataGridViewColumn,
		this.uxPredracunDataGridViewColumn,
		this.uxIDParentDataGridViewColumn,
		this.uxIDPrebrojavanjaDataGridViewColumn			});
			this.uxDokumentTipDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxDokumentTipDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxDokumentTipDataGridView.Name = "uxDokumentTipDataGridView";
			this.uxDokumentTipDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxDokumentTipDataGridView.TabIndex = 0;	
			this.uxDokumentTipDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxDokumentTipDataGridView.EnableHeadersVisualStyles = false;
			this.uxDokumentTipDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnDokumentTipDataGridViewDataError);
			this.uxDokumentTipDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDokumentTipDataGridViewCellValueNeeded);
			this.uxDokumentTipDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDokumentTipDataGridViewCellValuePushed);
			
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = false;		
			//
			// uxNazivDataGridViewColumn
			//
			this.uxNazivDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxNazivDataGridViewColumn.DataPropertyName = "Naziv";
			this.uxNazivDataGridViewColumn.HeaderText = "Naziv";
			this.uxNazivDataGridViewColumn.Name = "uxNazivDataGridViewColumn";
			this.uxNazivDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxNazivDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxNazivDataGridViewColumn.ReadOnly = false;		
			//
			// uxOblikSifreDataGridViewColumn
			//
			this.uxOblikSifreDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxOblikSifreDataGridViewColumn.DataPropertyName = "OblikSifre";
			this.uxOblikSifreDataGridViewColumn.HeaderText = "OblikSifre";
			this.uxOblikSifreDataGridViewColumn.Name = "uxOblikSifreDataGridViewColumn";
			this.uxOblikSifreDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxOblikSifreDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxOblikSifreDataGridViewColumn.ReadOnly = false;		
			//
			// uxSmjerDataGridViewColumn
			//
			this.uxSmjerDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxSmjerDataGridViewColumn.DataPropertyName = "Smjer";
			this.uxSmjerDataGridViewColumn.HeaderText = "Smjer";
			this.uxSmjerDataGridViewColumn.Name = "uxSmjerDataGridViewColumn";
			this.uxSmjerDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxSmjerDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxSmjerDataGridViewColumn.ReadOnly = false;		
			//
			// uxRezervacijaDataGridViewColumn
			//
			this.uxRezervacijaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxRezervacijaDataGridViewColumn.DataPropertyName = "Rezervacija";
			this.uxRezervacijaDataGridViewColumn.HeaderText = "Rezervacija";
			this.uxRezervacijaDataGridViewColumn.Name = "uxRezervacijaDataGridViewColumn";
			this.uxRezervacijaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxRezervacijaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxRezervacijaDataGridViewColumn.ReadOnly = false;		
			//
			// uxPredracunDataGridViewColumn
			//
			this.uxPredracunDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxPredracunDataGridViewColumn.DataPropertyName = "Predracun";
			this.uxPredracunDataGridViewColumn.HeaderText = "Predracun";
			this.uxPredracunDataGridViewColumn.Name = "uxPredracunDataGridViewColumn";
			this.uxPredracunDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxPredracunDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxPredracunDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDParentDataGridViewColumn
			//
			this.uxIDParentDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDParentDataGridViewColumn.DataPropertyName = "IDParent";
			this.uxIDParentDataGridViewColumn.HeaderText = "IDParent";
			this.uxIDParentDataGridViewColumn.Name = "uxIDParentDataGridViewColumn";
			this.uxIDParentDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDParentDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDParentDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDPrebrojavanjaDataGridViewColumn
			//
			this.uxIDPrebrojavanjaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDPrebrojavanjaDataGridViewColumn.DataPropertyName = "IDPrebrojavanja";
			this.uxIDPrebrojavanjaDataGridViewColumn.HeaderText = "IDPrebrojavanja";
			this.uxIDPrebrojavanjaDataGridViewColumn.Name = "uxIDPrebrojavanjaDataGridViewColumn";
			this.uxIDPrebrojavanjaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDPrebrojavanjaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDPrebrojavanjaDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxDokumentTipDataGridView);
			this.Name = "DokumentTipDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentTipErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentTipDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDokumentTipBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				DokumentTipDataGridViewEventArgs args = new DokumentTipDataGridViewEventArgs();
				args.DokumentTip = _currentDokumentTip;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class DokumentTipDataGridViewEventArgs : System.EventArgs
		{
			private Entities.DokumentTip	_DokumentTip;
	
			/// <summary>
			/// the  Entities.DokumentTip instance.
			/// </summary>
			public Entities.DokumentTip DokumentTip
			{
				get { return _DokumentTip; }
				set { _DokumentTip = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxDokumentTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentTipDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxDokumentTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentTipDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDokumentTipDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						e.Value = DokumentTipList[e.RowIndex].ID;
						break;
					case "uxNazivDataGridViewColumn":
						e.Value = DokumentTipList[e.RowIndex].Naziv;
						break;
					case "uxOblikSifreDataGridViewColumn":
						e.Value = DokumentTipList[e.RowIndex].OblikSifre;
						break;
					case "uxSmjerDataGridViewColumn":
						e.Value = DokumentTipList[e.RowIndex].Smjer;
						break;
					case "uxRezervacijaDataGridViewColumn":
						e.Value = DokumentTipList[e.RowIndex].Rezervacija;
						break;
					case "uxPredracunDataGridViewColumn":
						e.Value = DokumentTipList[e.RowIndex].Predracun;
						break;
					case "uxIDParentDataGridViewColumn":
						e.Value = DokumentTipList[e.RowIndex].IDParent;
						break;
					case "uxIDPrebrojavanjaDataGridViewColumn":
						e.Value = DokumentTipList[e.RowIndex].IDPrebrojavanja;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxDokumentTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDokumentTipDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDokumentTipDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						DokumentTipList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
					case "uxNazivDataGridViewColumn":
						DokumentTipList[e.RowIndex].Naziv = (System.String)e.Value;
						break;
					case "uxOblikSifreDataGridViewColumn":
						DokumentTipList[e.RowIndex].OblikSifre = (System.String)e.Value;
						break;
					case "uxSmjerDataGridViewColumn":
						DokumentTipList[e.RowIndex].Smjer = (System.Int32)e.Value;
						break;
					case "uxRezervacijaDataGridViewColumn":
						DokumentTipList[e.RowIndex].Rezervacija = (System.Int32)e.Value;
						break;
					case "uxPredracunDataGridViewColumn":
						DokumentTipList[e.RowIndex].Predracun = (System.Int32)e.Value;
						break;
					case "uxIDParentDataGridViewColumn":
						DokumentTipList[e.RowIndex].IDParent = (System.Int32?)e.Value;
						break;
					case "uxIDPrebrojavanjaDataGridViewColumn":
						DokumentTipList[e.RowIndex].IDPrebrojavanja = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
